#include "LogicUndo.h"

string LogicUndo::undo(stack< Data >& undoStackData, vector<Task>& tasksVector,
						Writer* _writer, Data* _data){

	string statusMessage;				
	
	try{
		
		if( undoStackData.size() != 1 ) {
		
		tasksVector.clear();
		undoStackData.pop();
		undoStackData.top().getAll( tasksVector );
		// load and write will destroy the contents if tasksvector is subdisplay of the orginal 
		// list of tasks
		_writer->write( tasksVector );
		_data->executeLoad( tasksVector );
		statusMessage = UNDO_SUCCESS_MESSAGE;

	}

	else {

		statusMessage = UNDO_ERROR_MESSAGE;

	}

	return statusMessage;

   }

	catch( CustomException& e ){

		statusMessage = "Exception : "+e.getMessage();
		return statusMessage;

	}

	catch (...) {

		statusMessage = "Unknown exception ";
		return statusMessage;
	}

}

const string LogicUndo::UNDO_SUCCESS_MESSAGE = "Undo Successful";

const string LogicUndo::UNDO_ERROR_MESSAGE = "Unable to Undo Further";
